package com.tree.thrive.business.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * top-tree
 *
 * @Auther: cheng.tang
 * @Date: 2023/1/9 6:53 PM
 * @Description:
 */
@Slf4j
@Service
public class TaskServiceImpl implements TaskService {

    private volatile static boolean startTask = false;

    @Async
    @Override
    public void doTask() {
        log.info("任务执行开始 startTask {} ", startTask);
        while (startTask) {
            log.info("doTask ...... startTask ");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException ignored) {
            }
        }
        log.info("任务执行结果 startTask {} ", startTask);
    }

    @Override
    public void startTask() {
        startTask = true;
        log.info("startTask startTask {} ", startTask);
    }

    @Override
    public void stopTask() {
        startTask = false;
        log.info("stopTask startTask {} ", startTask);
    }


}
